/**
 * 
 */
package jfengao.oauth.client.common;

import java.util.Base64;

import jfengao.oauth.client.GrantTypes;
import jfengao.oauth.client.OauthInfo;

/**
 * @author gaofeng
 * @date 2018年9月17日
 */
public class OauthString {

	public OauthString() {
	}
	
	public static final String wwwBasicAuth(String u,String p) {
		StringBuilder auth = new StringBuilder();
		auth.append(u).append(":").append(p);
		return "Basic " + Base64.getEncoder().encodeToString(auth.toString().getBytes()); 
	}

	public static final String builderURI(OauthInfo authInfo) {
		String gType = authInfo.getGrantType();
		StringBuilder sb = new StringBuilder(authInfo.getServer()).append("?");
		sb.append("grant_type=").append(gType);
		sb.append("&scope=").append(authInfo.getScope()); 
		if (GrantTypes.Client_Credentials.equals(gType)) {
		} else if (GrantTypes.Password.equals(gType)) {
			sb.append("&username=").append(authInfo.getUsername());
			sb.append("&password=").append(authInfo.getPasswd());
		} else if (GrantTypes.Implicit.equals(gType)) {
		} else if (GrantTypes.Authorization_code.equals(gType)) {
			sb.append("&code=").append(authInfo.getCode());
			sb.append("&redirect_uri=").append(authInfo.getRedirectUrl()); 
		}
		return sb.toString();
	}

}
